package com.tanhua.server.controller;

import com.tanhua.model.em.CommentType;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;




    @GetMapping("/userinfo")
    //为了更好的页面效果，需要展示出用户的基本信息
    public ResponseEntity messagesUserinfo(String huanxinId){
        UserInfoVo vo=messagesService.findUserInfoByHuanxin(huanxinId);
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/contacts")//添加好友
    public ResponseEntity addFriend(@RequestBody Map map){
        Integer obj = (Integer)map.get("userId");
        Long frindId = Long.valueOf(obj);
        messagesService.contacts(frindId);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/contacts")
    public  ResponseEntity findFriend(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      String keyword    ){

       PageResult pr= messagesService.findFriends(page,pagesize,keyword);
       return ResponseEntity.ok(pr);
        }


        //喜欢列表
    @GetMapping("/loves")
   public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr=messagesService.findLovesMeUser(page,pagesize);
        return ResponseEntity.ok(pr);

    }

    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        CommentType commentType = CommentType.LIKE;
        PageResult pr=messagesService.findLikesMeUser(page,pagesize,commentType);
        return ResponseEntity.ok(pr);

    }
    @GetMapping("/comments")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        CommentType commentType = CommentType.COMMENT;
        PageResult pr=messagesService.findLikesMeUser(page,pagesize,commentType);
        return ResponseEntity.ok(pr);

    }
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        CommentType commentType = CommentType.COMMENT;
        PageResult pr=messagesService.findLikesMeUser(page,pagesize,commentType);
        return ResponseEntity.ok(pr);

    }

}
